<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
			<input type="hidden"  id="communicateId" name="communicateId" value="${communicateId }"/>
			<input type="hidden"  id="recommendId" name="recommendId" value="${recommend.id }"/>
			<c:if test="${ not empty record}">
			<input type="hidden"  id="id" name="id" value="${record.id }"/>
			</c:if>
			<div class="form-group">
				<label class="col-sm-3 control-label">入职时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="entryDate" name="entryDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" placeholder="请选择日期" value="${record.entryDate }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">试用期结束日期：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="probation" name="probation" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" placeholder="请选择日期" value="${record.probation }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">入职岗位：</label>
				<div class="col-sm-8">
				    <c:if test="${ not empty record.inPost}">
					<input type="text" class="form-control" id="inPost" name="inPost" value="${record.inPost }"/>
					</c:if>
					 <c:if test="${ empty record.inPost}">
					<input type="text" class="form-control" id="inPost" name="inPost" value="${recommend.posts }"/>
					</c:if>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">入职薪酬：</label>
				<div class="col-sm-8 form-inline">
				    <select class="form-control"  id="tax" name="tax">
				        <option value="">==请选择==</option>
				        <option value="1" <c:if test="${record.tax eq 1}">selected</c:if>>==税前==</option>
				        <option value="2" <c:if test="${record.tax eq 2}">selected</c:if>>==税后==</option>
				    </select>
				    <select class="form-control"  id="salary" name="salary">
				        <option value="">==请选择==</option>
				        <option value="1" <c:if test="${record.salary eq 1}">selected</c:if>>==月薪==</option>
				        <option value="2" <c:if test="${record.salary eq 2}">selected</c:if>>==年薪==</option>
				    </select>
					<div id="monthly" style="display: none;"><input type="text" class="form-control" id="monthlySalary" name="monthlySalary" value="${record.monthlySalary }" />（元）<input type="text" class="form-control" id="month" name="month"  value="${record.month }">（月）</div>
					<div id="annual" style="display: none;"><input type="text" class="form-control" id="annualSalary" name="annualSalary" value="${record.annualSalary }" />（元）</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">薪酬详细：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="payDetail" name="payDetail" value="${record.payDetail }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">offer文件：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="filePath" name="filePath" readonly="readonly" placeholder="选择文件点击上传" value="${record.filePath }"/>
					<input type="file" name="file" id="file" onchange="uploadfile();" style="display: none;" >
					<button type="button"  class="btn btn-warning" onclick="$('input[id=file]').click();" >上传</button>
					<c:if test="${not empty record.filePath}">
					<a href="<%=contextPath%>${record.filePath }"  class="btn btn-info" target="_blank">预览</a>
					</c:if>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" value="${record.remark }"/>
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12 form-inline">
					<c:if test="${ not empty record}">
						<button class="btn btn-warning" type="button" id="sub_update">更新</button>
					</c:if>
					<button class="btn btn-primary" type="button" id="sub">新增</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
    	var salary = '${record.salary}';
    	if(salary==1){
    		$("#monthly").show();
    	}else if (salary==2) {
    		$("#annual").show();
		}
    	$("#salary").change(function(){
    		var num = $(this).val();
    		if(num==1){
    			$("#monthly").show();
    			$("#annual").hide();
    		}else if (num == 2) {
				$("#annual").show();
				$("#monthly").hide();
			}else {
				$("#annual").hide();
    			$("#monthly").hide();
			}
    	});
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('entryDate','入职时间未填写!'),
        	  new Array('probation','试用期未填写!'),
        	  new Array('inPost','入职岗位未填写!'),
        	  new Array('entryPay','入职薪酬未填写!'),
        	  new Array('payDetail','薪酬详细未填写!'),
        	  new Array('tax','税后税前未选择!'),
        	  new Array('salary','年薪月薪未选择!'),
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/demandOfferRecord/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
        $("#sub_update").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('entryDate','入职时间未填写!'),
        	  new Array('probation','试用期未填写!'),
        	  new Array('inPost','入职岗位未填写!'),
        	  new Array('entryPay','入职薪酬未填写!'),
        	  new Array('payDetail','薪酬详细未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/demandOfferRecord/update',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
    function uploadfile() {
    	var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
        if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
            return;
        }
        if(fileObj!=""){
    	var formData = new FormData();
    	formData.append("action", "UploadVMKImagePath");
        formData.append("files", $("#file")[0].files[0]);
    	$.ajax({
          	  	         type:'POST',
          	  	         url:'<%=contextPath%>/upload/uploadFile',
          	  	         data:formData,
          	  	         contentType:false,
          	  	         processData:false,//这个很有必要，不然不行
          	  	         dataType:"json",
          	  	         mimeType:"multipart/form-data",
          	  	         success:function(data){
          	  		      console.log(data);
          	  	                if(data.code==200){
          	  	                    $("#filePath").val(data.path);
          	  	                }
          	  	            }
          	  	     });
		}else {
			swal("错误", "请选择文件", "error");
		}
	}
	</script>
</body>
</html>